import requests
import re

#url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=261084177'
url = 'https://api.bilibili.com/x/v1/dm/list.so?oid=261836995'
headers = {
     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
}
response = requests.get(url, headers=headers)
doc = response.content.decode('utf-8')
format = re.compile('<d.*?>(.*?)</d>')
Danmu = format.findall(doc)
with open("bzhan.txt", 'w', encoding='utf-8') as f:
    for i in Danmu:
        f.write(i + '\r\n')
        print(i)
